<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>餐桌列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
    <style>
        #urlqr img{margin:0 auto}
    </style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-header">餐桌列表</div>
            <blockquote class="layui-elem-quote">客人用餐后，请使用手机端后台“餐桌管理”清台，后续客人可继续点餐</blockquote>

            <div class="layui-card-body" pad15>
            <div class="layui-col-md4" style="padding-bottom:10px">
                <a class="layui-btn layuiadmin-btn-list" href="javascript:void(0)" onclick="openmax('{:url('edit')}')">添加</a>
                <button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="datadel(0)">删除</button>
                <button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="createTable()">批量生成</button>
            </div>
            <div class="layui-col-md12">
                <table id="tabledata" lay-filter="tabledata"></table>
            </div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: "{$Request.url}" //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
          {type:"checkbox"},
          {field: 'id', title: 'ID',  width:80},
          {field: 'name', title: '名称'},
          {field: 'pic', title: '图片', templet: '<div>{{# if(d.pic){ }}<img src="{{d.pic}}" style="height:60px"/>{{# } }}</div>'},
          {field: 'cid', title: '分类', width:80, templet: function (d) {
                  if (d.category !== null) return d.category.name;
                  return '';
              }
          },
          {field: 'seat', title: '座位数', width:80},
          {field: 'sort', title: '排序',width:80},
          //{field: 'createtime', title: '创建时间',templet:function(d){ return date('Y-m-d H:i',d.createtime)},width:150},
          
          {field: 'canbook', title: '预定',templet:function(d){ if(d.canbook==1) return '<span style="color:#008000">开启</span>'; else if(d.canbook==0) return '<span style="color:red">关闭</span>';},width:80},
          
          {field: 'status', title: '状态',templet:function(d){ if(d.status==1) return '<span style="color:#008000">预定</span>'; else if(d.status==-1) return '<span style="color:red">禁用</span>'; else if(d.status==0) return '<span style="color:green">空闲</span>'; else if(d.status==2) return '<span style="color:orange">入座</span>'; else if(d.status==3) return '<span style="color:orange">清台</span>';},width:80},
          {field: 'operation', title: '操作',templet: function(d){
				var html = '';
				html += '<button class="table-btn" onclick="openmax(\'{:url('edit')}/id/'+d.id+'\')">编辑</button>';
                  html += '<button class="table-btn" onclick="showurl('+d.id+')">查看链接和二维码</button>';
				html += '<button class="table-btn" onclick="datadel('+d.id+')">删除</button>';
				if(d.deep==0 || d.deep==1){
					html += '<button class="table-btn" onclick="openmax(\'{:url('edit')}/pid/'+d.id+'\')">添加子分类</button>';
				}
				return html;
      },width:250}
    ]]
  });
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
  function showurl(id){
      var pagepath = 'restaurant/shop/index?tableId='+id;
    pagepath = pagepath + '&bid=' + {$bid};
    viewLink(pagepath);
  }
	//删除
	function datadel(id){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				 return layer.msg('请选择数据');
			}
			var ids = [];
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id)
		}
		layer.confirm('确定要删除吗?',{icon: 7, title:'操作确认'}, function(index){
			//do something
			layer.close(index);
			var index = layer.load();
			$.post("{:url('del')}",{ids:ids},function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				tableIns.reload()
			})
		});
	}
      //生成桌台
      function createTable(){
          
          var html = '<div style="margin:20px auto;">';
          html+='<div class="layui-form form-label-w8" lay-filter="">';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">桌台数量：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="number" name="makecount" value="5" class="layui-input">';
          html+='		</div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">所属分类：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<select name="cid"  lay-verify="required">';
          html+='			    <option value="">--选择分类--</option>';
          {foreach $tableCategory as $cate}
          html+='			    <option value="{$cate[\'id\']}">{$cate.name}</option>';
          {/foreach}
          html+='			</select>';
          html+='		</div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">名称前缀：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="text" name="prefix" value="" placeholder="请输入餐桌名称的前缀，例如“A”" class="layui-input">';
          html+='		</div><div class="layui-form-mid layui-word-aux" style="margin-left:10px;">例如：“A”</div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">起始序号：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="text" name="start" value="1" placeholder="请输入起始序号" class="layui-input">';
          html+='		</div><div class="layui-form-mid layui-word-aux" style="margin-left:10px;">默认1</div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">不包含的数字：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="text" name="not_have_number" value="" placeholder="不包含的数字,英文逗号“,”隔开" class="layui-input">';
          html+='		</div><div class="layui-form-mid layui-word-aux" style="margin-left:10px;">例如：“1,2”</div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">座位数：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="number" min="1" max="200" name="seat" value="" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">';
          html+='	    </div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">预定：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='		<input type="radio" name="canbook" value="0" title="关闭" >';
          html+='       <input type="radio" name="canbook" value="1" title="开启" >';
          html+='	    </div>';
          html+='	</div>';
          
          
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">绑定打印机：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
           
          {foreach $printArr as $k=>$v}
          html+='			<input type="checkbox" name="print_ids[]" value="{$k}" title="{$v}" lay-skin="primary">';
           {/foreach}
           html+='	    </div>';
           html+='      <div class="layui-form-mid layui-word-aux" style="margin-left:160px;">普通场景在菜品中绑定打印区域即可，此处绑定打印机适合包间对应多个吧台出单的场景</div>';      
          html+='	</div>';
          
          html+='	<div class="layui-form-item" style="margin-top:30px">';
          html+='		<label class="layui-form-label"></label>';
          html+='		<div class="layui-input-inline">';
          html+='			<button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit_create">确 定</button>';
          html+='		</div>';
          html+='	</div>';
          html+='</div>';
          html+='</div>'
              
              console.log(html);
          var makelayer = layer.open({type:1,area: ['600px', '470px'],title:'批量创建桌台',content:html,shadeClose:true})
          layui.form.render();
          layui.form.on('submit(submit_create)', function(obj){
              var field = obj.field;
              if(field.cid ==''){
                  return layer.msg('请选择分类');
              }
              var index= layer.load();
              $.post("{:url('createTables')}",field,function(data){
                  layer.close(index);
                  layer.close(makelayer)
                  dialog(data.msg,data.status);
                  tableIns.reload()
              })
          })
      }
	</script>
	{include file="public/copyright"/}

</body>
</html>